import dataList from '@/components/dataList'
import {realEstatePage, realEstateDelect} from '../api/propertietar'
export default {
    name: "real-estate",
    components: {dataList},
    provide() {
        return {
            initList: this.getListData,
        };
    },
    beforeMount() {
        this.getListData();
    },
    data()  {
        return {
            // 表单绑定
            tableData: [],
            // 请求参数
            params: {
                current: 1,
                size: 10,
                cardType: '10',
                assetName: ''
            },
            //筛选组
            selectDataArr: [],
            // 分页
            pager: {
                total: 0, // 总页数
                current: 1, // 当前页数
                size: 10 // 每页显示多少条
            },
            // 页面loading
            loading: false,
            filterList: [{ label: '登记日期', inputType: 'daterange', name: ['registrationDateStart','registrationDateEnd']}],
            // 证件类型
            cardTypes: [
                {
                    value: '10',
                    label: '仅有不动产证'
                },
                {
                    value: '20',
                    label: '移交协议'
                },
                {
                    value: '30',
                    label: '第三方评估机构报告'
                }
            ],
            cardType: '10',
						warehousingStatus: []
        }
    },
    methods: {
        //分页请求
        getListData(params = {}){
            this.loading = true
            let requestData = {...this.params, ...params}
            realEstatePage(requestData).then(res => {
                const  {current, size, total, records} = res.data.data
                this.tableData = records
                this.params = requestData
                this.pager = {total, current, size}
            }).finally(() => {
                this.loading = false
            })
        },
        //证件类型转换
        getCardTypeValue(cardType){
            let arr = this.cardTypes.filter(e=>e.value === cardType)
            if (arr.length > 0) {
                return arr[0].label
            } else {
                return cardType
            }
        },
        //新增
        handleToAdd() {
            this.$router.push({name: "proprietary_add", params: {cardType: this.cardType}});
        },
        //编辑
        handleToEdit(row) {
            this.$router.push({name: "proprietary_edit", params: {id: row.assetFixedWarehousingId}});
        },
        // 查看
        handleToLook(row) {
            this.$router.push({name: "proprietary_look", params: {id: row.assetFixedWarehousingId}});
        },
        //删除
        deleteData() {
            if (this.selectDataArr.length == 0) {
                this.$alert("请勾选要删除的数据！");
                return false;
            }
            let ids = []
						let warehousingStatus = []
            this.selectDataArr.map(item => {
                this.warehousingStatus.push(item.warehousingStatus)
                if (item.warehousingStatus !== 0) {
										warehousingStatus.push(item.warehousingStatus)
                } else {
									ids.push(item.assetFixedWarehousingId)
								}
            });
						if (warehousingStatus.length > 0) {
							this.$message.error('只能删除未入库数据！')
							return false;
						}
            this.warehousingStatus.some(it => {
                if (it === 0) {
                    this.$confirm("此操作将永久删除该数据, 是否继续?", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }).then(() => {
                    	realEstateDelect(ids).then((rep) => {
                            this.$message({
                                type: "success",
                                message: "删除成功!",
                            });
                            this.getListData();
                        }).catch((e) => {
                            this.$message({
                                type: "success",
                                message: "删除失败!",
                            });
                        });
                    }).catch(() => {
                        this.$message({
                            type: "info",
                            message: "已取消删除",
                        });
                    });
                }
            })
        },
        // 菜单点击监听
        handleMenuClick(type){
            switch (type) {
                case 'add':
                    this.handleToAdd()
                    break;
                case 'delete':
                    this.deleteData();
                    break;
                default:
                    this.$message(type)
                    break;
            }
        }
    }
}
